﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YServer;
using GameProtocol;
using ServerApp.Logic;
using ServerApp.Logic.Fight;

namespace ServerApp
{
    public class HandlerCenter:AbsHandlerCenter
    {
        /// <summary>
        /// 登录 & 注册 消息处理
        /// </summary>
        public IMessageReceive login=new LoginHandler();
        public IMessageReceive match = new MatchHandler();
        public IMessageReceive fight = new FightHandler();

        public override void OnClientConnect(YToken token)
        {
            Console.WriteLine("客户端连接");
            token.Send(new SocketModel(0,0,0,"你已连接"));
        }

        public override void OnClientMessage(YToken token, SocketModel model)
        {
            switch (model.type)
            {
                case TypeProtocol.Login:
                    login.OnMessageReceive(token, model);
                    break;
                case TypeProtocol.Match:
                    match.OnMessageReceive(token, model);
                    break;
                case TypeProtocol.Fight:
                    fight.OnMessageReceive(token, model);
                    break;
                default:
                    break;
            }
        }

        public override void OnClientClose(YToken token, string error)
        {
            Console.WriteLine(error);
            match.OnClientClose(token, error);
            login.OnClientClose(token,error);
            fight.OnClientClose(token, error);
        }
    }
}
